package com.cn;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author 作者： cm
 * @DATE 创建时间： 2021/8/23 11:58
 * @Version 版本：1.0
 */
@Slf4j
@Component
public class ContextFileListener implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    private FileMonitor fileMonitor;
    @Resource
    private FileListener fileListener;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
            fileMonitor.setFileListener(fileListener);
            fileMonitor.start();
        }
    }
}

